package org.pine.api.beans.request;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

/**
 * 分页请求体
 *
 * @author pine
 * @version 1.0
 * @since 2025-04-10 17:40
 */
@Data
@Schema(description = "分页请求体")
@JsonIgnoreProperties(ignoreUnknown = true)
public class PageRequest<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = -1864501014587272603L;

    @Schema(title = "分页数据", description = "分页数据")
    private T data;

    @Schema(title = "分页大小", description = "分页大小", defaultValue = "20")
    private Long pageSize;

    @Schema(title = "分页页码", description = "分页页码", defaultValue = "1")
    private Long pageNum;


    public void setDefaultParam() {
        if (Objects.isNull(pageSize)) {
            this.pageSize = 20L;
        }

        if (Objects.isNull(pageNum)) {
            this.pageNum = 1L;
        }
    }
}
